﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    dangnhap dnkh = new dangnhap();
    protected void btnLogin_Click1(object sender, EventArgs e)
    {
        if (dnkh.DangNhap(txtUser.Text, txtPass.Text) == true)
        {
            if (chkNhoMK.Checked)
            {
                Response.Cookies["LoginUser"]["KhachHangID"] = dnkh.KhachHangID.ToString();
                Response.Cookies["LoginUser"]["TenDangNhap"] = dnkh.TenDangNhap;
                Response.Cookies["LoginUser"]["MatKhau"] = dnkh.MatKhau;
                Response.Cookies["LoginUser"]["QuyenHan"] = dnkh.QuyenHan.ToString();
                Response.Cookies["LoginUser"]["HoTen"] = dnkh.HoTen;
                Response.Cookies["LoginUser"]["SoDT"] = dnkh.HoTen;
                Response.Cookies["LoginUser"]["DiaChi"] = dnkh.Diachi;
                Response.Cookies["LoginUser"]["Email"] = dnkh.Email;
                Response.Cookies["LoginUser"].Expires = DateTime.Now.AddDays(7);
                Response.Redirect("Default.aspx");
            }
            else
            {
                Session["KhachHangID"] = dnkh.KhachHangID.ToString();
                Session["TenDangNhap"] = dnkh.TenDangNhap;
                Session["MatKhau"] = dnkh.MatKhau;
                Session["QuyenHan"] = dnkh.QuyenHan.ToString();
                Session["HoTen"] = dnkh.HoTen;
                Session["SoDT"] = dnkh.HoTen;
                Session["DiaChi"] = dnkh.Diachi;
                Session["Email"] = dnkh.Email;
                Response.Redirect("Default.aspx");
            }

        }
        else
        {
            lblError.Visible = true;
            lblError.Text = "Tên đăng nhập hoặc mật khẩu sai";
        }
    }
}